faApp.controller('SimuBuyInfoListCtrl',['$scope','simuBuyInfoService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyInfoService,simuService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 
  $scope.jjbm = $routeParams.jjbm;
  if (!$scope.jjbm){
    $location.path("/simu/list");
    return;
  }
  

  $scope.list = [];
  $scope.loading = true;
  $scope.jj = [];
  
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
    $scope.item.createBy = $scope.jj.createBy;
  });

	$scope.$watch('config',function(){
    simuBuyInfoService.list($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1,
    "jjbm" : $routeParams.jjbm || "",
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	}; 

  $scope.remove = function(id){
    simuBuyInfoService.remove(id).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $route.reload();
      }
    });
  };
}]);

faApp.controller('SimuBuyInfoAddCtrl',['$scope','simuBuyInfoService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyInfoService,simuService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 
  $scope.jjbm = $routeParams.jjbm;
  if (!$scope.jjbm){
    $location.path("/simu/list");
    return;
  }

  $scope.item = {};
  $scope.loading = true;
  $scope.jj = [];
  
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
    $scope.item.jjbm = $scope.jj.jjbm;
    $scope.item.jjmc = $scope.jj.jjmc;
  }); 
  
  $scope.save = function(){
    if (!$scope.form.$invalid){
      simuBuyInfoService.add($scope.item).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          $location.path("/simu/buyinfo/list").search({jjbm:$scope.item.jjbm});
        }
      });
      
    }else{
      alert("请先完整填写表单");
    }
  };

}]);

faApp.controller('SimuBuyInfoEditCtrl',['$scope','simuBuyInfoService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyInfoService,simuService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 
  $scope.item = {};
  $scope.id = $routeParams.id;
  $scope.jjbm = $routeParams.jjbm;
  $scope.loading = true;
  $scope.jj = [];
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail; 
  }); 
  simuBuyInfoService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.item = json.detail||{};
    if($scope.item.buyNoticeDetail==undefined||$scope.item.buyNoticeDetail==''){
      //style='font-family: 微软雅黑;font-size: 16px;'
       $scope.item.buyNoticeDetail = "<p class='p-c-title'><span ><a name='rgfl'></a>认购费率：</span></p><p class='p-c-title'><span ><a name='glfl'></a>管理费率：</span></p><p class='p-c-title'><span ><a name='shfl'></a>赎回费率：</span></p><p class='p-c-title'><span ><a name='tgfl'></a>托管费率：</span></p><p class='p-c-title'><span ><a name='yjfc'></a>业绩分成：</span></p><p class='p-c-title'><span ><a name='shsm'></a>赎回说明：</span></p>";
    }
    $scope.loading = false; 
  });
  $scope.save = function(){
    if (!$scope.form.$invalid){
      $scope.item.jjbm = $scope.jj.jjbm;
      $scope.item.jjmc = $scope.jj.jjmc;
      simuBuyInfoService.edit($scope.item).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          alert("修改成功");
          $route.reload();
        }
      });
    }else{
      alert("请先完整填写表单");
    }
  };
}]);

faApp.controller('SimuBuyInfoViewCtrl',['$scope','simuBuyInfoService','$location','$controller','$route','$routeParams',function($scope,simuBuyInfoService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.id = $routeParams.id;
  $scope.loading = true;

  simuBuyInfoService.query({id:$scope.id}).then(function(json){
    $scope.item = json.detail;
    $scope.loading = false;
  });

  $scope.remove = function(id){
    simuBuyInfoService.remove(id).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $route.reload();
      }
    });
  };

}]);





